<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>

	
<title>悦章科技机构平台</title>	

	
<script src="/Public/static/jquery-2.0.3.min.js"></script>
<script src="/Public/static/layer/layer.js"></script>
<script src="/Public/static/jPages.js"></script>
<!--内容样式-->
<link rel="stylesheet" href="__PUBLIC__/Home/css/style.css" />
<link rel="stylesheet" href="__PUBLIC__/Home/css/page.css" />
<style>
    .holder a{border:1px solid #e1e1e1;color:#909090;cursor:pointer;}
    .jp-current{padding:6px 6px;border:1px solid #e1e1e1;background:#f55555;cursor:pointer;}
    .holder .jp-current{color:#fff;cursor:pointer;}
    .page{margin: 0 0 0 0}
</style>

	
	
</head>

<body>

	
	<div class="main">
	
	
		<!--  头部  -->

		
		
		
		<!--  左侧导航  -->
		<include file="menu" />
		
		
		
		<!--  右侧内容  -->
		<div class="content">
			
			
			<div class= "ct-title">
				<div class="ctt-bt">新增优惠券</div>
				<div class="divclear"></div>
			</div>
			<form action="" method="POST">
				<div class="ct-xz">
					<div class="ctx-box">
						<div class="ctxb-l">优惠券名称：</div>
						<div class="ctxb-r">
							<input type="text" placeholder="请输入优惠券名称" class="ctxbr-wb" name="name">
						</div>
						<div class="divclear"></div>
					</div>
					<div class="ctx-box">
						<div class="ctxb-l">发行数量：</div>
						<div class="ctxb-r">
							<input type="text" placeholder="请输入发行数量" class="ctxbr-wb" name="count">
							<div class="ctxbr-dw">张</div>
						</div>
						<div class="divclear"></div>
					</div>
					<div class="ctx-box">
						<div class="ctxb-l">连续签到第：</div>
						<div class="ctxb-r">
							<input type="text" placeholder="" class="ctxbr-wb" name="get_day">
							<div class="ctxbr-dw">天获得</div>
						</div>
						<div class="divclear"></div>
					</div>
					<div class="ctx-box">
						<div class="ctxb-l">有效期：</div>
						<div class="ctxb-r">
							<input type="text" placeholder="请输入有效期天数" class="ctxbr-wb" name="use_day">
							<div class="ctxbr-dw">天</div>
						</div>
						<div class="divclear"></div>
					</div>
					<div class="ctx-box">
						<div class="ctxb-l">每人限领：</div>
						<div class="ctxb-r">
							<input type="text" placeholder="请输入每人限领数量" class="ctxbr-wb" name="get_count">
							<div class="ctxbr-dw">张</div>
						</div>
						<div class="divclear"></div>
					</div>
					<div class="ctx-box">
						<div class="ctxb-l">使用门槛：</div>
						<div class="ctxb-r">
							<span>满</span>
							<input type="text" placeholder="" class="ctxbr-wb2" name="min_price">
							<span>减</span>
							<input type="text" placeholder="" class="ctxbr-wb2" name="deduct_price">
							<span>元</span>
							<div class="divclear"></div>
						</div>
						<div class="divclear"></div>
					</div>
					<div class="ctx-box" style="width: 100%;">
						<div class="ctxb-l">适用商品：</div>
						<div class="ctxb-r" style="width: 300px;">
							<select class="ctxbr-xl zz" name="type" onchange="dd()">
								<option value="1">全部商品</option>
								<option value="2">指定商品</option>
							</select>
						</div>
						<div class="tzb">
							<div class="ctxb-xz" onclick="showCourse()">选择</div>
							<div class="ctxb-yx">当前已选<input name="nm" style="border: 0;margin: 0;padding: 0;outline: none;width:10px;">个</div>
							<div class="divclear"></div>
						</div>
						<div class="ctxb-sp">


							<div class="divclear"></div>
						</div>
					</div>
					<div class="divclear"></div>
					<button class="ctx-btn" type="submit">确认</button>
				</div>
			</form>
			
		</div>
		
		
		
	</div>
		
		
	
	
	<!-- 选择课程 弹出框-->
	<div class="tck-demo" id="tck-xzkc">
		
		<div class="tk-box">
			<div class="tkb-title">
				<div class="tkbt-bt">选择课程</div>
				<div class="tkbt-close" onClick="document.getElementById('tck-xzkc').style.display='none'">
					<img src="__PUBLIC__/Home/images/icon_delete.png" />
				</div>
				<div class="divclear"></div>
			</div>
			<div class="tkb-fpxs">
				<div class="tkbf-top">
					<select class="tkbft-xl type" onchange="demo()" name="category">
						<option value="1">面授课</option>
						<option value="2">点播课</option>
						<option value="3">直播课</option>
					</select>
					<select class="tkbft-xl yi" onchange="dem()" name="one_type_id" id="one">
						<option>一级类别</option>
					</select>
					<select class="tkbft-xl er" name="two_type_id" id="two">
						<option>二级类别</option>
					</select>
					<input type="text" class="tkbft-wb2" placeholder="输入课程名称搜索" name="name">
					<button class="tkbft-ss" id="sub">搜索</button>
					<div class="divclear"></div>
				</div>
				<div class="tkbf-img" id="itemContainer">
					<volist name="course" id="item">
						<div class="tkbfi-box">
							<div class="tkbfib-pic">
								<img src="{$item.img}" />
							</div>
							<div class="tkbfib-bt">{$item.name}</div>
							<input type="checkbox" class="tkbfib-an" name="course" value="{$item.id}">
						</div>
					</volist>
					<div class="divclear"></div>
				</div>
			</div>
			<div class="tkb-btn" style="width: auto;padding: 0;float: left;margin: 20px 0 0 20px;">
	            <div class="page">
	                <div class="holder" style="font-size:12px;"></div>
	            </div>
	        </div>
			<div class="tkb-qr qd" style="float: right;margin: 15px 20px 0 0;">确定选择</div>
			<div class="divclear"></div>
		</div>
		
	</div>
		
		
	
	
	
</body>
</html>
<script type="text/javascript">
	$(document).ready(function(){
		$('.tzb').hide();
    	var type=$('.type option:selected').val();
    	$("select[name='category']").val(type);
        $.ajax({
            url:"{:U('Marketing/getTypes')}",
            data:{category:type},
            dataType:'json',
            type:'post',
            success:function(data){
            	// console.log(data.data.parent);return false;
            	var tt='';
                $.each(data.data.parent,function(k,v){
                	// console.log(v);return false;
                 tt +='<option value='+v.id+'>'+v.name+'</option>';
                });
                $('.yi').html(tt);

                var hh='';
                $.each(data.data.child,function(k,v){
                 hh +='<option value='+v.id+'>'+v.name+'</option>';
                });
            	$('.er').html(hh);
            }
        })
	});
	//选择面授 点播 直播 的时候会触发这个事件，默认是面授课不触发这个
	function demo(){
        var type=$('.type option:selected').val();
        $("select[name='category']").val(type);
        $.ajax({
            url:"{:U('Marketing/getTypes')}",
            data:{category:type},
            dataType:'json',
            type:'post',
            success:function(data){
            	// console.log(data);return false;

                var tt='';
                $.each(data.data.parent,function(k,v){
                 tt +='<option value='+v.id+'>'+v.name+'</option>';
                });
                $('.yi').html(tt);


                var hh='';
                $.each(data.data.child,function(k,v){
                 hh +='<option value='+v.id+'>'+v.name+'</option>';
                });
            	$('.er').html(hh);
            }
        })
    }

    //选择一级分类的时候，二级分类变动
	function dem(){
		var type=$('.type option:selected').val();
		$("select[name='category']").val(type);
        var pid=$('.yi option:selected').val();
        $.ajax({
            url:"{:U('Marketing/getChildTypes')}",
            data:{pid:pid,category:type},
            dataType:'json',
            type:'post',
            success:function(data){
                var hh='';
                $.each(data.data,function(k,v){
                 hh +='<option value='+v.id+'>'+v.name+'</option>';
                });
            	$('.er').html(hh);
            }
        })
    }
    //选择是全部商品还是指定商品的时候
	function dd(){
		var type=$('.zz option:selected').val();
		if(type==1){
			$('.tzb').hide();
		}else{
			$('.tzb').show();
		}
	}
    //点击搜索的时候
    $("#sub").click(function(){
    	// alert(432);return false;
    	var category=$('.type option:selected').val();
    	$("select[name='category']").val(category);
    	var type_id=$('.er option:selected').val();
    	if(type_id ==''){
    		alert('请选择二级分类');return false;
    	}
    	var name=$("input[name='name']").val();
    	$.ajax({
            url:"{:U('Marketing/getCourses')}",
            data:{type_id:type_id,category:category,name:name},
            dataType:'json',
            type:'post',
            success:function(data){
            	// console.log(data);return false;
            	var hh='';
                $.each(data.data,function(k,v){
                hh+='<div class="tkbfi-box">';
				hh+='<div class="tkbfib-pic">';
				hh+='<img src="'+v.img+'" />';
				hh+='</div>';
				hh+='<div class="tkbfib-bt">'+v.name+'</div>'
				hh+='<input type="checkbox" class="tkbfib-an" name="course" value="'+v.id+'">'
				hh+='</div>';
                });
            	$('.tkbf-img').html(hh);
            	$("div.holder").jPages({
                    containerID : "itemContainer",
                    perPage: 8
                });
            }
        })
    })
    $(".qd").click(function(){

    	var chk_value =[];
		    $("input[type='checkbox']:checked").each(function(){
		    chk_value.push($(this).val());
	    });

    	
    	// $("input[name='course_id']").val(course_id);
    	var one_type_id=$("#one").val()
    	$("input[name='one_type_id']").val(one_type_id);
    	 var one_type_id=$("#two").val()
    	$("input[name='two_type_id']").val(one_type_id);

		
    	//我要跟据分类跟课程ID显示
    	var category=$("select[name='category']").val();
    	// console.log(category);return false;
    	$("input[name='category']").val(category);
    	$.ajax({
    		url:"{:U('Marketing/getCourselist')}",
            data:{course_id:chk_value,category:category},
            dataType:'json',
            type:'post',
            success:function(data){
            	// console.log(data.data);return false;
            	var tt='';
                $.each(data.data,function(k,v){
				tt+='<div class="xbnt-kc">';
				tt+='<div class="xbntk-img">';
				tt+='<img src="'+v.img+'" />';
				tt+='</div>';
				tt+='<div class="xbntk-wz">';
				tt+='<h3>'+v.name+'</h3>';
				tt+='<h4>'+v.category_name+'</h4>';
				tt+='</div>';
				tt+='<div class="xbntk-sc">';
				tt+='<img src="__PUBLIC__/Home/images/icon_sc.png" />';

				tt+='<input type="hidden" name="cate_id[]" value="'+v.category+'">';
				tt+='<input type="hidden" name="good_id[]" value="'+v.id+'">';
				tt+='</div>';
				tt+='<div class="divclear"></div>';
				tt+='</div>';
                });
                $('.ctxb-sp').append(tt);
                var len=$('.xbnt-kc').size();
                $("input[name='nm']").val(len);
            }
    	}) 
    	$('.tck-demo').hide();
    })

    $('body').on('click','.xbntk-sc', function(){
    	$(this).parent('.xbnt-kc').remove();
        var len=$('.xbnt-kc').size();
        $("input[name='nm']").val(len);
    })
                //显示课程弹出框
    function showCourse()
    {
        $("#tck-xzkc").show();
        $("div.holder").jPages({
            containerID : "itemContainer",
            perPage: 8
        });
    }
</script>